package com.welsmann.app.start.spider.dao;

import java.util.List;

import com.welsmann.app.start.spider.dao.helper.QueryHelper;
import com.welsmann.app.start.spider.entity.SimpleAirQuality;

public class SimpleAirQualityDAO {

	private final static String _tn = "simpleairquality";

	public static SimpleAirQuality latest() {
		return QueryHelper.single(SimpleAirQuality.class, "select * from "
				+ _tn + " order by publish desc limit 1", null);
	}

	/**
	 * 获取所有
	 * 
	 * @return
	 */
	public static List<SimpleAirQuality> findAll() {
		return QueryHelper.list(SimpleAirQuality.class, "select * from " + _tn
				+ " order by publish", null);
	}

	/**
	 * 根据主键获取
	 * 
	 * @param id
	 * @return
	 */
	public static SimpleAirQuality find(String id) {
		return QueryHelper.single(SimpleAirQuality.class, "select * from "
				+ _tn + " where id = ?", id);
	}

	/**
	 * 新增
	 * 
	 * @param nt
	 * @return
	 */
	public static int insert(SimpleAirQuality nt) {
		return QueryHelper.update("insert into " + _tn + " values(?,?,?,?)",
				nt.getId(), nt.getPublish(), nt.getStatus(), nt.getNumber());
	}

	/**
	 * 更新
	 * 
	 * @param nt
	 * @return
	 */
	public static int update(SimpleAirQuality nt) {
		return QueryHelper.update("update " + _tn
				+ " set publish = ?,status = ?,number = ? where id = ?",
				nt.getPublish(), nt.getStatus(), nt.getNumber());
	}

	/**
	 * 对象删除
	 * 
	 * @param nt
	 * @return
	 */
	public static int delete(SimpleAirQuality nt) {
		return QueryHelper.update("delete from " + _tn + " where id  = ? ",
				nt.getId());
	}

	/**
	 * 对象删除
	 * 
	 * @param id
	 * @return
	 */
	public static int delete(String id) {
		return QueryHelper.update("delete from " + _tn + " where id  = ? ", id);
	}

}
